package Server.junit;

import common.exception.ExtinctionException;

import Server.players.Carnivorous;
import Server.players.Herbivorous;
import Server.players.Species;
import junit.framework.TestCase;

public class SpeciesTest extends TestCase {

	private Species<Carnivorous> sC;
	private Species<Herbivorous> sH;
	protected void setUp() throws Exception {
		super.setUp();
		this.sC = new Species<Carnivorous>("carni");
		this.sH = new Species<Herbivorous>("erbi");
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testSpeciesString() {
		this.sC = new Species<Carnivorous>("carni");
		this.sH = new Species<Herbivorous>("erbi");
		assertNotNull(this.sC);
		assertNotNull(this.sH);
	}

	public void testSpeciesSpeciesOfDinoType() {
		Species<?> s1 = new Species<Carnivorous>(this.sC);
		Species<?> s2 = new Species<Herbivorous>(this.sH);
		assertEquals(this.sC, s1);
		assertEquals(this.sH, s2);
	}

	public void testToString() {
		assertEquals(this.sC.toString(), "carni");
		assertEquals(this.sH.toString(), "erbi");
	}

	public void testGetDinoList() {
		Integer[] d = this.sC.getDinoList();
		assertTrue(d.length == 0);
		Carnivorous c = new Carnivorous(1);
		this.sC.addDino(c);
		d = this.sC.getDinoList();
		assertNotNull(d);
		assertTrue(d.length == 1);
		assertTrue(d[0] == 1);
	}

	public void testGetType() {
		this.sC.addDino(new Carnivorous(1));
		this.sH.addDino(new Herbivorous(2));
		assertTrue(this.sC.getType() == 'c');
		assertTrue(this.sH.getType() == 'e');
	}

	public void testCount() {
		assertTrue(this.sC.count() == 0);
		Carnivorous c = new Carnivorous(1);
		this.sC.addDino(c);
		assertTrue(this.sC.count() == 1);
	}

	public void testGet() {
		Carnivorous c = new Carnivorous(1);
		this.sC.addDino(c);
		assertEquals(c, this.sC.get(1));
	}

	public void testOlder() {
		int age = this.sC.getAge();
		try{
			this.sC.older();
		} catch (ExtinctionException e){
			fail();
		}
		assertTrue(age + 1 == this.sC.getAge());
	}

	public void testUpdateDinosAge() {
		Carnivorous c = new Carnivorous(1);
		int age = c.getAge();
		this.sC.addDino(c);
		this.sC.updateDinosAge();
		c = (Carnivorous)this.sC.get(1);
		assertTrue(age + 1 == c.getAge());
	}

	public void testRemove() {
		Carnivorous c = new Carnivorous(1);
		this.sC.addDino(c);
		this.sC.remove(c);
		assertTrue(this.sC.count() == 0);
	}

}
